home *** CD-ROM | disk | FTP | other *** search
- /* sMOVIEtext.c - function to smooth scroll text up through a view.
- M. J. Round. 7 - Oct - 1989. */
-
-
- /* This does NOT scroll by moving huge chunks of memory about.
- What happens is like this..... (are you sitting comfortably?)....
-
- 1. We have a bitmap that is higher than what you can see on screen
- - actually just over twice as high. To start with, you can only see
- the top part of the bitmap on your screen.
-
- 2. The text is written to the part of the bitmap which is off the
- bottom of the screen (where you can't see it) and then the bitmap
- is scrolled up to bring the new text into view. This happens one
- line of text at a time (one line for each call to this function).
- Note that NO memory has to be moved to do the scroll - we just
- ask the co-processor to display a different chunk of bitmap on the
- screen. (Thanks Amiga!).
-
- 3. Unfortunately we don't have an infinitely big bitmap so comes the
- time when we have to swap back to showing the top part of the
- bitmap... (This is the clever bit).....
-
- 4. As we write text to the part of the bitmap which is off the bottom
- of the currently display, we also COPY it to the part of the
- bitmap which is off the TOP of the current display. When we get
- near to the bottom of the bitmap, there is already a perfect copy
- of the current screen up near the top of the bitmap - so we switch
- that into view and start all over. (phew!)
-
- 5. There is no number 5.
-
- I'm sure there must be easier ways of doing this - I can think of at
- least four - but this seemed elegant to me.
- */
-
-
- #include "sMOVIE.h"
-
- extern int maxfontheight,abort_prog;
-
- extern int mousemonitor(void);
-
- extern int maxwidth;
-
- extern int delay; /* delay between each pixel scroll */
-
- extern int ypos; /* y posn of previous text base */
-
- extern struct View v; /* view to be smooth scrolled */
-
- extern struct RastPort rp; /* rastport to write text to */
-
- void smoothtext (text,length,xpos,apen,bpen,f)
-
- char *text; /* the text to be printed */
- short length; /* length of text (in chars NOT pixels) */
- short xpos; /* x position to start text (in pixels) */
- BYTE apen; /* foreground (ink colour) pen */
- BYTE bpen; /* background (paper colour) pen */
- struct TextFont *f; /* the font in use (open it elsewhere) */
-
- { /* NOTE: This always works as if JAM2 mode were selected */
-
- int j,ysize,baseline,underhang,jump,hipos,chunk;
-
- register int i;
-
- WORD *ryoffset;
-
- ysize = f->tf_YSize;
- ryoffset = &(v.ViewPort->RasInfo->RyOffset);
-
- for(i=0; i < ysize; i++) { /* each pass scrolls one pixel */
- switch(i) {
-
- case 1:
- /* jump to top of bitmap if necessary */
- underhang = ysize - (baseline = f->tf_Baseline);
- ypos += baseline;
- jump = v.ViewPort->DHeight + maxfontheight;
- if (ypos >= (rp.BitMap->Rows - underhang)) {
- ypos -= jump;
- *ryoffset -= jump;
- }
- SetAPen(&rp,bpen);
- SetOPen(&rp,bpen);
- SetDrMd(&rp,JAM1);
- SetFont(&rp,f); /* select desired font */
- hipos = ypos - jump;
- chunk = length >> 2;
- if (!abort_prog) abort_prog = mousemonitor();
- break;
-
- case 2:
- /* clear line to background colour - ready for text */
- RectFill(&rp,0,ypos-baseline,maxwidth-1,ypos+underhang);
- Move(&rp,xpos,ypos); /* position ready to write */
- SetAPen(&rp,apen);
- if (!abort_prog) abort_prog = mousemonitor();
- break;
-
- case 3: /* done like this 'cos "Text" */
- case 4: /* is too slow to manage a */
- case 5: /* whole line in 1/60 sec. */
- Text(&rp,text,chunk);
- text += chunk;
- length -= chunk;
- break;
-
- case 6:
- Text(&rp,text,length); /* print text in four chunks */
- break;
-
- case 7:
- /* copy the text up to the top part of the bitmap...
- ....(sometimes we don't need to...) */
- if((hipos >= baseline) && (*ryoffset >= (hipos + underhang)))
- ClipBlit(&rp,0,ypos-baseline /* source posn */
- ,&rp,0,hipos-baseline /* dest posn */
- ,maxwidth,ysize /* size */
- ,0xc0 /* direct copy */
- );
- else if (!abort_prog) abort_prog = mousemonitor();
- break;
-
- default :
- if (!abort_prog) abort_prog = mousemonitor();
- break;
- } /* end of switch */
-
- ++(*ryoffset);
- MakeVPort(&v, v.ViewPort);
- MrgCop(&v);
-
- for (j=0; j<delay; j++)
- WaitTOF();
-
- LoadView(&v); /* scroll up one pixel */
- } /* repeat (height of font) times */
-
- ypos += underhang;
-
- } /* end of sMOVIEtext */
-